#!/usr/bin/python
# -*- coding: UTF-8 -*-

import xlwt
import db


table_name = '联系人名单'
table_name1 = '部门表'
#'部门表'包含省总机关各部门、各驻会产业工会（工委）
table_name2 = '非驻会产业工会表'
table_name3 = '市总表'
#table_name4 = '委员表'
#table_name5 = '经审委员表'

#print(db.getallmess(table_name1))
#print(db.getallmess(table_name))
#print(db.getno('办公室'))

#print(db.getmessbyid(table_name,'部门ID',1))


def w2xls():
    wb = xlwt.Workbook()
    ws = wb.add_sheet('sheet')

    # 设置字体，字号（仿宋_GB2312，14）song_font
    song_font = xlwt.Font()
    song_font.name = '仿宋_GB2312'
    song_font.height = 280  # 字体大小，220就是11号字体，大概就是11*20得来的吧

    # 设置字体，字号（黑体，14）black_font
    black_font = xlwt.Font()
    black_font.name = '黑体'
    black_font.height = 300









    row = 0
    deptup = db.getallmess(table_name1)
    for i in deptup:
        row += 1
        col = 0
        depname = i[1]
        depno = i[0]
        print(depname)
        ws.write(row,col,depname)
        row += 1
        depmess = db.getmessbyid(table_name, '部门ID', depno, '内部顺序')
        for j in depmess:
            ws.write(row,col,j[0])
            col += 1
            if col == 6:
                row += 1
                col = 0

    wb.save(r'C:\Users\Administrator\Desktop\1.xls')

w2xls()

